﻿@using System.Reflection;
@using YUCodeGen.Utils;
@model PropertyInfo[]
@{
    Layout = null;

    string classname = (string)ViewData["ClassName"];
    string cat = "list";

    string compName = $"{classname.ToLower()}-{cat}";
    string compClassname = $"{classname}{PageUtil.Capitalize(cat)}";
}
import {Component,OnInit} from '@@angular/core';
import { HttpClient, HttpResponse } from '@@angular/common/http';
import {SysConfig,DataTablesResponse} from '../System/SystemConfig';

@@Component({
    selector: '@compName',
    templateUrl:'@(compName).component.html',
    styleUrls:["@(compName).component.css"]
    })
export class @(compClassname)Component{

    dtOptions: DataTables.Settings = {};
    data: any[];

    constructor(private http: HttpClient) {}

    ngOnInit(): void {
    const that = this;

    this.dtOptions = {
    pagingType: 'full_numbers',
    pageLength: 10,
    serverSide: true,
    processing: true,
    ajax: (dataTablesParameters: any, callback) => {
        that.http.post<DataTablesResponse>(SysConfig.apiRoot+'/@compClassname',dataTablesParameters,{})
            .subscribe(resp => {
                that.data = resp.data;
                callback({
                    recordsTotal: resp.recordsTotal,
                    recordsFiltered: resp.recordsFiltered,
                    data: []
                });
            });
        },
    columns: [
            @foreach (PropertyInfo pinfo in Model)
            {
            if (PageUtil.IsListFiled(pinfo))
            {
                @:{data:'@(pinfo.Name)'},
            }
            }
    ]
    };
  }
}